<!DOCTYPE HTML>
<html lang="zh-cn">

<head>
    #include("../include/header.html")
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-title">
                    <h5>用户管理 </h5>

                </div>
                <div class="ibox-content">
                    #include("../include/message.html")

                    <!-- 工具栏 -->
                    <div class="row" style="margin-bottom: 6px;">
                        <div class="col-sm-12">
                            <div class="pull-left">
                                <button class="btn btn-white btn-sm" data-toggle="tooltip" data-placement="left"
                                        onclick="add()" title="添加"><i class="fa fa-plus"></i> 添加
                                </button>
                                <script type="text/javascript">
                                    function add() {
                                        openDialog("新增" + '字典', "/dict/form");
                                    }
                                </script>

                                <button class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="left"
                                        onclick="batchDelete()" title="批量删除"><i class="fa fa-plus"></i> 批量删除
                                </button>
                                <script type="text/javascript">
                                    //批量删除
                                    function batchDelete() {
                                        //获取所有被选中的记录
                                        var rows = $("#paginationTable").bootstrapTable('getSelections');
                                        if (rows.length === 0) {
                                            alert("请先选择要删除的记录!");
                                            return;
                                        }
                                        var ids = '';
                                        for (var i = 0; i < rows.length; i++) {
                                            ids += rows[i]['id'] + ",";
                                        }
                                        ids = ids.substring(0, ids.length - 1);
                                        confirmx("确定删除吗？", '/dict/delete?id=' + ids);
                                    }
                                </script>

                                <!-- 增加按钮 -->
                                <button class="btn btn-white btn-sm " data-toggle="tooltip" data-placement="left"
                                        onclick="refresh()" title="刷新"><i class="glyphicon glyphicon-repeat"></i> 刷新
                                </button>
                                <script type="text/javascript">
                                    function refresh() {//刷新
                                        window.location = "/dict";
                                    }
                                </script>

                            </div>
                        </div>
                    </div>

                    <table id="paginationTable" data-class="table table-hover table-condensed"></table>

                </div>
            </div>
        </div>
    </div>
</div>

#include("../include/footer.html")
<script>
    var module = '${module}';
    $(function () {
        $('#paginationTable').bootstrapTable({
            url: '/' + module + '/getList',
            method: 'get',
            pagination: true,  //表格底部显示分页条
            sidePagination: "server",
            escape: false, //启动转义字符
            pageSize: 10, //每页显示多少条数据
            pageNumber: 1, //初始化翻页的页码
            pageList: [10, 25, 50, 100],
            queryParamsType: '',//设置请求参数格式
            queryParams: function queryParams(params) {   //设自定义查询参数
                var param = {
                    pageSize: params.pageSize,   //每页多少条数据
                    pageNo: params.pageNumber, // 页码
                };
                return param;
            },
            columns: [
                {
                    checkbox: true,
                    visible: true                  //是否显示复选框
                },
                {field: 'id', title: 'ID'},
                {field: 'name', title: '名称'},
                {field: 'value', title: '值'},
                {field: 'created', title: '创建时间'},
                {field: 'modified', title: '更新时间'},
                {field: 'operator', title: '操作', formatter: 'operateFormatter'}]
        })
    });

    // 格式化按钮
    function operateFormatter(value, row, index) {
        var arr = [];
        var view = '<a href="#" onclick="openDialogView(\'查看\', \'/' + module + '/form?id=' + row.id + '\')" class="btn btn-info btn-xs"><i class="fa fa-search-plus"></i> 查看</a> \n';
        var update = '<a href="#" onclick="openDialog(\'修改\', \'/' + module + '/form?id=' + row.id + '\')"  class="btn btn-primary btn-xs"><i class="fa fa-edit"></i> 修改</a> \n';
        var del = '<a href="/' + module + '/delete?id={{row.id}}" onclick="return confirmx(\'确定删除吗？\', this.href)" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> 删除</a> \n';

        arr.push(view);
        arr.push(update);
        arr.push(del);
        return arr.join('');

    }
</script>
</body>
</html>